<?php

/**
 * Miembro filter form base class.
 *
 * @package    universidad
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseMiembroFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'rut'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'nombres'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'paterno'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'materno'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'fecha_nacimiento' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'correo'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'celular'          => new sfWidgetFormFilterInput(),
      'fijo'             => new sfWidgetFormFilterInput(),
      'contrasena'       => new sfWidgetFormFilterInput(array('with_empty' => false)),
      're_contrasena'    => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'estado'           => new sfWidgetFormChoice(array('choices' => array('' => '', 'Activado' => 'Activado', 'Desactivado' => 'Desactivado'))),
      'comuna_id'        => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Comuna'), 'add_empty' => true)),
      'created_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'perfil_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Perfil')),
    ));

    $this->setValidators(array(
      'rut'              => new sfValidatorPass(array('required' => false)),
      'nombres'          => new sfValidatorPass(array('required' => false)),
      'paterno'          => new sfValidatorPass(array('required' => false)),
      'materno'          => new sfValidatorPass(array('required' => false)),
      'fecha_nacimiento' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'correo'           => new sfValidatorPass(array('required' => false)),
      'celular'          => new sfValidatorPass(array('required' => false)),
      'fijo'             => new sfValidatorPass(array('required' => false)),
      'contrasena'       => new sfValidatorPass(array('required' => false)),
      're_contrasena'    => new sfValidatorPass(array('required' => false)),
      'estado'           => new sfValidatorChoice(array('required' => false, 'choices' => array('Activado' => 'Activado', 'Desactivado' => 'Desactivado'))),
      'comuna_id'        => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Comuna'), 'column' => 'id')),
      'created_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'perfil_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Perfil', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('miembro_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addPerfilListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.PerfilMiembro PerfilMiembro')
      ->andWhereIn('PerfilMiembro.perfil_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Miembro';
  }

  public function getFields()
  {
    return array(
      'id'               => 'Number',
      'rut'              => 'Text',
      'nombres'          => 'Text',
      'paterno'          => 'Text',
      'materno'          => 'Text',
      'fecha_nacimiento' => 'Date',
      'correo'           => 'Text',
      'celular'          => 'Text',
      'fijo'             => 'Text',
      'contrasena'       => 'Text',
      're_contrasena'    => 'Text',
      'estado'           => 'Enum',
      'comuna_id'        => 'ForeignKey',
      'created_at'       => 'Date',
      'updated_at'       => 'Date',
      'perfil_list'      => 'ManyKey',
    );
  }
}
